RCAD script
1.00
tree
treeup.bmp
treedown.bmp
4
0
1
Min
Max
Itérations
Amplitude (degrés)






2
4
5
135






Dim s_Pi, s_x1, s_y1, s_x2, s_y2, s_long, s_amplitude as double
Dim s_minb, s_maxb, s_deltab, s_nbituser as integer

sub Do_Branches(fx1 as double,fy1 as double,fx2 as double,fy2 as double, nb_it as integer, s_ep as double)
Dim s_angle1, s_angle2, s_long2, s_deltaangle, s_dx, s_dy, f_angle, fx3, fy3, s_coef_L as double
Dim L_nbit, s_i , s_k as integer

   if nb_it < s_nbituser then
      //Calcul angle
      s_dx = fx1 - fx2
      s_dy = fy1 - fy2
  
      if s_dx <> 0 then
         s_angle1 = abs(Atan(s_dy / s_dx))
         if s_dx > 0 then
            if s_dy < 0 then
               s_angle1 = 6.283185307179586 - s_angle1
            end if
         else
            if s_dy > 0 then
               s_angle1 = 3.141592653589793 - s_angle1
            else
               s_angle1 = 3.141592653589793 + s_angle1
            end if
         end if
      else
         if s_dy = 0 then
            s_angle1 = 0
         else
            if s_dy > 0 then
               s_angle1 = 1.570796326794897
            else
               s_angle1 = 4.71238898038469
            end if
         end if
      end if

      L_nbit = nb_it+1
      s_k = s_minb + round(s_deltab * Rnd)
      s_deltaangle = s_amplitude / s_k
      s_long2 = s_long / (L_nbit * 2)
      for s_i = 1 to s_k
         s_angle2 = s_angle1 + s_Pi / 2 + (s_Pi - s_amplitude) / 2 + s_deltaangle * (s_i - 1) + s_deltaangle * Rnd
         Do
             s_coef_L = Rnd
         Loop until s_coef_L > 0.5
         fx3 = fx2 + s_long2 * cos(s_angle2) * s_coef_L
         fy3 = fy2 + s_long2 * sin(s_angle2) * s_coef_L
         Add_Line(fx2,fy2,fx3,fy3,s_ep,7,false,false,false, 100)
         Do_Branches(fx2,fy2,fx3,fy3, L_nbit, s_ep/2)
      next
   end if
end sub

//Main
s_Pi = 3.141592653589793
s_minb = val(userinput1)
s_maxb = val(userinput2)
s_deltab = s_maxb - s_minb
s_nbituser = val(userinput3)
s_amplitude = val(userinput4) *s_Pi / 180
s_x1 = (lastx + firstx) / 2
//s_y1 = Max(firsty, lasty)
if firsty > lasty then
    s_y1 = firsty
    s_long = lasty
else
    s_y1 = lasty
    s_long = firsty
end if
//s_long = s_y1 - Min(firsty, lasty)
s_long = s_y1 - s_long
s_y2 = s_y1 - s_long / 2

//tronc
Add_Line(s_x1,s_y1,s_x1,s_y2,16,7,false,false,false, 100)

//1 = it�ration
Do_Branches(s_x1, s_y1, s_x1, s_y2, 1,8)
